<?php

//by carboleda 20130927
class carteraclienteControlador extends Controlador 
{
	
	public function __construct()
	{
		parent::__construct();
		$this->_vista->asignartJs( array( 'carteracliente' ) );
		$this->_carteraclienteDAO = $this->cargarModelo( "carteracliente" );
	}

	public function index()
	{
		//Sesion::accesoControlado( array( 'usuario' ) );
		$this->_vista->titulo = 'Bienvenido...';		
		$this->_vista->render('carteracliente');
	}

	public function cargarlista() {
		$lista = $this->obtenerVcadena( "lista" );
		$filtro = $this->obtenerVcadena( "filtro" );
		$esMultiple = $this->obtenerVcadena( "esMultiple" );

	    try {
	        $lstRet = $this->_carteraclienteDAO->cargarlista($lista, $filtro, $esMultiple);

	        if(isset($lstRet)) {
		        echo json_encode(array(
		                    'success' => TRUE,
		                    'lista_ret' => $lstRet
		                ));
	        }
	    } catch (Exception $e) {
	        echo "ERROR->" . $e;
	        echo "<option value='-1'>Error</option>";
	    }
	}

	public function consultar_carteracliente() {
		$fecha_inicial = $this->obtenerVcadena( "fecha_inicial" );
		$fecha_final = $this->obtenerVcadena( "fecha_final" );
		$almacen = $this->obtenerVcadena( "almacen" );
		$linea = $this->obtenerVcadena( "linea" );
		$cliente = $this->obtenerVcadena( "cliente" );
		$departamento = $this->obtenerVcadena( "departamento" );
		$producto = $this->obtenerVcadena( "producto" );

		$jsonCate = array();
		$jsonSeriesCan = array();
		$jsonSeriesDin = array();

		try {
	        $lstRet = $this->_carteraclienteDAO->consultar_carteracliente($fecha_inicial, $fecha_final, $almacen, 
	        	$linea, $cliente, $departamento, $producto);

	        if(isset($lstRet)) {
	        	$strHtml = "<table class='table table-bordered' width='auto'>";
	        	$strHtml .= "<tr>";
	        	$strHtml .= "<th>No. Factura</th>";
	        	$strHtml .= "<th>Cedula</th>";
	        	$strHtml .= "<th>Nombre</th>";
	        	$strHtml .= "<th>Cupo Credito</th>";
	        	$strHtml .= "<th>Cupo Maximo</th>";
	        	$strHtml .= "<th>Cupo Disponible</th>";
	        	$strHtml .= "<th>Total Deuda</th>";
	        	$strHtml .= "<th>Fecha</th>";
	        	$strHtml .= "</tr>";

	        	if(sizeof($lstRet) > 0) {
		        	$rg_rc;
		        	for( $i = 0; $i < sizeof($lstRet); $i++){
						$rg_rc = $lstRet[$i];

						//$jsonCate[] = $rg_rc["clientecedula"]."-".$rg_rc["clientenombre"];

						$strHtml .= "<tr>";
						$strHtml .= "<td>". $rg_rc["nofactura"]."</td>";
						$strHtml .= "<td>". $rg_rc["cli_cedula"]."</td>";
						$strHtml .= "<td>". $rg_rc["cli_nombre"]."</td>";
						$strHtml .= "<td>". $rg_rc["cli_cupocredito"]."</td>";
						$strHtml .= "<td>". $rg_rc["cart_cupo_maximo"]."</td>";
						$strHtml .= "<td>". $rg_rc["cart_cupo_disponible"]."</td>";
						$strHtml .= "<td>". $rg_rc["cart_total_deuda"]."</td>";
						$strHtml .= "<td>". $rg_rc["fecha"]."</td>";
						$strHtml .= "</tr>";
		            }
		        } else {
		        	$strHtml .= "<tr>";
					$strHtml .= "<td colspan='8'>No se encontraron datos.</td>";
					$strHtml .= "</tr>";
		        }

	            $strHtml .= "</table>";

		        echo $strHtml;
	        }
	    } catch (Exception $e) {
	        echo "ERROR->" . $e;
	    }
	}

}

?>